package com.hoperun.product.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.hoperun.distributecloth.R;
import com.hoperun.product.base.BaseActivity;
import com.hoperun.product.util.LanguageUtil;
import com.hoperun.product.view.SimpleDialog;

public class TraySettingActivity extends BaseActivity implements OnClickListener {
	public  final static String EXTRA_ANSWER_WEIGHT="TraySettingActivity.weight";
	public final static String EXTRA_ANSWER_PACKAGE="TraySettingActivity.package";
	public final static String EXTRA_ANSWER_PACKAGE_TYPE="TraySettingActivity.packageType";
	public final static String EXTRA_ANSWER_PACKAGE_WEIGHT="TraySettingActivity.packageWeight";
	private EditText weightEt;
	private Button greenBtn;
	private Button yellowBtn;
	private Button redBtn;
	private Button blackBtn;
	private Button aBtn;
	private Button bigBtn;
	private Button smallBtn;
	private Button noneBtn;
	private Button okBtn;

	private String mPackage="";
	private String mPackageType="";
	private String mPackageWeight="";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tray_setting_activity);
		initView();
		initEvent();
	}

	private void initView() {
		weightEt = (EditText) findViewById(R.id.tray_setting_weightTv);
		greenBtn = (Button) findViewById(R.id.tray_setting_greenBtn);
		yellowBtn = (Button) findViewById(R.id.tray_setting_yellowBtn);
		redBtn = (Button) findViewById(R.id.tray_setting_redBtn);
		blackBtn = (Button) findViewById(R.id.tray_setting_blackBtn);
		aBtn = (Button) findViewById(R.id.tray_setting_aBtn);
		bigBtn = (Button) findViewById(R.id.tray_setting_bigBtn);
		smallBtn = (Button) findViewById(R.id.tray_setting_smallBtn);
		noneBtn = (Button) findViewById(R.id.tray_setting_noneBtn);
		okBtn = (Button) findViewById(R.id.tray_setting_okBtn);




				if(LanguageUtil.getLanguageStr().contains("vi")){
					blackBtn.setText("合(7.4kg)");
				}else{
					blackBtn.setText("黑(3.2kg)");

				}

	}

	private void initEvent() {

		greenBtn.setOnClickListener(this);
		yellowBtn.setOnClickListener(this);
		redBtn.setOnClickListener(this);
		blackBtn.setOnClickListener(this);
		aBtn.setOnClickListener(this);
		bigBtn.setOnClickListener(this);
		smallBtn.setOnClickListener(this);
		noneBtn.setOnClickListener(this);
		okBtn.setOnClickListener(this);

	}

	/**
	 * 设置所有按钮为灰色
	 */
	private void setAllBtnGray(){
		greenBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		yellowBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		redBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		blackBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		aBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		bigBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		smallBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		noneBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_gray_1));
		
	}
//	@Override
//	public boolean dispatchKeyEvent(KeyEvent event) {
//		//toast("dispatchKeyEvent" + event.getKeyCode() + "");
//		// 拦截物理键盘事件
//		//拦截回车键
//		if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
//			if (event.getAction() == KeyEvent.ACTION_DOWN) {
//				// mScanGun.isMaybeScanning(event.getKeyCode(), event);
//				return true;
//			}
//			return true;
//		}
//		return super.dispatchKeyEvent(event);
//	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tray_setting_greenBtn:
			setAllBtnGray();
			greenBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_green_dark_1));
			mPackage="纸管"+greenBtn.getText().toString();
			mPackageType="纸管绿";
			mPackageWeight="2.1";
			break;
		case R.id.tray_setting_yellowBtn:
			setAllBtnGray();
			yellowBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_yellow_dark_1));
			mPackage="纸管"+yellowBtn.getText().toString();
			mPackageType="纸管黄";
			mPackageWeight="2.5";
			break;

		case R.id.tray_setting_redBtn:
			setAllBtnGray();
			redBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_red_1));
			mPackage="纸管"+redBtn.getText().toString();
			mPackageType="纸管红";
			mPackageWeight="2.9";
			break;

		case R.id.tray_setting_blackBtn:
			setAllBtnGray();
			blackBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_black_light_1));	
			mPackage="纸管"+blackBtn.getText().toString();
			//mPackageType="纸管黑";
			//mPackageWeight="3.2";
			if(LanguageUtil.getLanguageStr().contains("vi")){
				mPackageType="纸管合";
				mPackageWeight="7.4";
			}else{
				mPackageType="纸管黑";
				mPackageWeight="3.2";
			}



			break;

		case R.id.tray_setting_aBtn:
			setAllBtnGray();
			aBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_blue_light_1));
			mPackage="布袋"+aBtn.getText().toString();
			mPackageType="布袋A";
			mPackageWeight="0.5";
			break;

		case R.id.tray_setting_bigBtn:
			setAllBtnGray();
			bigBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_blue_light_1));
			mPackage="箩筐"+bigBtn.getText().toString();
			mPackageType="箩筐大";
			mPackageWeight="15";
			break;

		case R.id.tray_setting_smallBtn:
			setAllBtnGray();
			smallBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_blue_light_1));
			mPackage="箩筐"+smallBtn.getText().toString();
			mPackageType="箩筐小";
			mPackageWeight="11";
			break;

		case R.id.tray_setting_noneBtn:
			setAllBtnGray();
			noneBtn.setBackground(getResources().getDrawable(R.drawable.btn_corner_blue_light_1));
			mPackage="箩筐"+noneBtn.getText().toString();
			mPackageType="箩筐无";
			mPackageWeight="0";
			break;

		case R.id.tray_setting_okBtn:
			String weight=weightEt.getText().toString().trim();
			if(TextUtils.isEmpty(mPackage)){
				SimpleDialog.show(this, getResources().getString(R.string.please_choose_one_package));
				return;
			}
			if(TextUtils.isEmpty(weight)){
				SimpleDialog.show(this,getResources().getString(R.string.please_input_tray_weight) );
				return;
			}
			Intent intent=new Intent();
			intent.putExtra(EXTRA_ANSWER_WEIGHT, weight);
			intent.putExtra(EXTRA_ANSWER_PACKAGE, mPackage);
			intent.putExtra(EXTRA_ANSWER_PACKAGE_TYPE, mPackageType);
			intent.putExtra(EXTRA_ANSWER_PACKAGE_WEIGHT, mPackageWeight);
			setResult(RESULT_OK, intent);
			finish();
			break;

		default:
			break;
		}
	}
	

	@Override
	public void onPostHandle(int requestType, Object objBody, boolean error) throws Exception {
		// TODO Auto-generated method stub

	}

}
